//
//  Entry.m
//  CEDict
//
//  Created by Eric Nadeau on 07-06-01.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "Entry.h"


@implementation Entry

+(bool) 
	contains: (NSString*) input 
	   query: (NSString*) query
{
	NSRange range = [input rangeOfString: query];
	bool retval = (range.location != NSNotFound);
	return retval;
}

+(bool) 
	oneOfContains: (NSArray*) inputs
			query: (NSString*) query
{
	NSEnumerator* enumerator = [inputs objectEnumerator];
	NSString* input;
	
	while( input = (NSString*)[enumerator nextObject] )
	{
		if( [Entry contains: input query: query] )
		{
			return true;
		}		
	}
	
	return false;
}

-(bool) matches: (NSString*)query
{
	bool retval =
		[Entry contains: simplified query: query]
		||
		[Entry contains: traditional query: query]
		||
		[Entry contains: pinyin query: query]
		||
		[Entry oneOfContains: english query: query]
	;
		
	return retval;
}

-(Entry*)	initWithSimplifed: (NSString*) s 
			andTraditional: (NSString*) t 
			andPinyin: (NSString*) p 
			andEnglish: (NSArray*) e
{
	simplified = s;
	traditional = t;
	pinyin = p;
	english = e;
	
	return self;
}

-(NSString*) simplified
{
	return simplified;
}

-(NSString*) traditional
{
	return traditional;
}

-(NSString*) pinyin
{
	return pinyin;
}

-(NSArray*) english
{
	return english;
}

@end
